#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3f;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = -1e18;
    for (int i = 0; i < n - 1; i++)
    {
        int m = max(a[i], a[i + 1]);
        int mex = 0;
        if (a[i] == 0 or a[i + 1] == 0)
        {
            mex++;
            if (a[i] == 1 or a[i + 1] == 1) mex++;
        }
        ans = max(ans, m - mex);
    }
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}